package cn.iocoder.yudao.module.train.controller.wechat.course;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.train.controller.admin.course.vo.CoursePageReqVO;
import cn.iocoder.yudao.module.train.controller.admin.course.vo.CourseRespVO;
import cn.iocoder.yudao.module.train.dal.dataobject.course.CourseDO;
import cn.iocoder.yudao.module.train.dal.dataobject.coursegroup.CourseGroupDO;
import cn.iocoder.yudao.module.train.service.course.CourseService;
import cn.iocoder.yudao.module.train.service.coursegroup.CourseGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.GET;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "小程序接口 - 课程管理")
@RestController
@RequestMapping("/wechat-api/course")
public class WechatCourseController {
    @Resource
    private CourseService courseService;
    /**
     * 课程列表
     */
    @GetMapping("/list")
    @Operation(summary = "获得课程列表")
    @ApiAccessLog(operateType = GET)
    public CommonResult<List<CourseRespVO>> getCourseList(@Valid CoursePageReqVO pageReqVO) {
        List<CourseDO> pageResult = courseService.getCourseListNoParam(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CourseRespVO.class));
    }

    /**
     * 课程详情
     */
    @GetMapping("/get")
    public CommonResult<CourseRespVO> get(Integer courseId) {
        if (courseId == null) {
            return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST);
        }
        CourseDO course = courseService.getCourse(courseId);
        return CommonResult.success(BeanUtils.toBean(course, CourseRespVO.class));
    }


}
